﻿using Blackbird.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using Mango.Communication;
namespace Blackbird.Game.Session
{
    /// <summary>
    /// A class to handle sessions.
    /// </summary>
    class SessionManager
    {
        /// <summary>
        /// The map to hold the sessions.
        /// </summary>
        private Dictionary<ServerSocket,HabboSession>SessionMap;

        /// <summary>
        /// The logging instance for the class.
        /// </summary>
        private Log log;

        /// <summary>
        /// The amount of clients connected.
        /// </summary>
        private int clients;
        /// <summary>

        /// <summary>
        /// Initialise a new instance of the Session Manager. This class must be kept as a singelton.
        /// </summary>
        
        public SessionManager()
        {
            this.SessionMap = new Dictionary<ServerSocket, HabboSession>();
        }

        /// Add a session to the map.
        /// </summary>
        /// <param name="socket">The socket on which the user is connected.</param>
        /// <returns>Return the session.</returns>


        public HabboSession AddSession(ServerSocket socket)
        {
            if (socket != null)
            {
                this.log = new Log("SessionManager");
                HabboSession Session = new HabboSession(this.clients++, socket);
                this.SessionMap.Add(socket, Session);
                //Session.Start();
                log.Info("Accepted session #id -> " + this.clients);
                return Session;
            }
            else 
            {
                throw new Exception("Session cannot be null!");
            }
        }
    }
}
